jQuery(document).ready(function () {		
	//Get district
	jQuery("select[name=city]").bind("change", changeCity);
	function changeCity() {		
		var id = jQuery(this).val();
		loadDistrict(id, "");
	}
	
	//Get ward
	jQuery("select[name=district]").bind("change", changeDistrict);
	function changeDistrict() {
		var id = jQuery(this).val();
		loadWard(id, "");
	}
	
	//Get district1
	jQuery("select[name=city1]").bind("change", changeCity1);
	function changeCity1() {		
		var id = jQuery(this).val();
		loadDistrictByForm(id, "", "addressForm");
	}
	
	//Get ward1
	jQuery("select[name=district1]").bind("change", changeDistrict1);
	function changeDistrict1() {
		var id = jQuery(this).val();
		loadWardByForm(id, "", "addressForm");
	}
});

function loadCity(selected) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-city",
		data: {},
		dataType: "html",
		success: function(response)
		{
			jQuery("select[name=city]").html(response);
			jQuery("select[name=city]").val(selected);
		}
	});
}

function loadDistrict(id, selected) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-district",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			jQuery("select[name=district]").html(response);
			jQuery("select[name=district]").val(selected);
		}
	});
}

function loadWard(id, selected) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-ward",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			jQuery("select[name=ward]").html(response);
			jQuery("select[name=ward]").val(selected);
		}
	});
}

function loadCityByForm(selected, formId) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-city",
		data: {},
		dataType: "html",
		success: function(response)
		{
			jQuery("form#" + formId + " select[name=city1]").html(response);
			jQuery("form#" + formId + " select[name=city1]").val(selected);
		}
	});
}
function loadDistrictByForm(id, selected, formId) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-district",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			jQuery("form#" + formId + " select[name=district1]").html(response);
			jQuery("form#" + formId + " select[name=district1]").val(selected);
		}
	});
}
function loadWardByForm(id, selected, formId) {
	jQuery.ajax({
		type: "POST",
		url: "/ajax-get-ward",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			jQuery("form#" + formId + " select[name=ward1]").html(response);
			jQuery("form#" + formId + " select[name=ward1]").val(selected);
		}
	});
}

